package Leetcode.ArrayAndLinkedList.hasCycle141;

import java.util.HashSet;
import java.util.Set;

/**
 * 该方案时间复杂度较高
 * 为快慢指针法的五百倍
 */

public class Solution2 {
    public boolean hasCycle(ListNode head) {
        Set<ListNode> list = new HashSet<>();
        while(head != null) {
            if(list.contains(head)) {
                return true;
            }
            list.add(head);
            head = head.next;
        }

        return false;
    }

}
